/**
    Die Ewigen Extension
    Copyright (C) 2011 DonKrieg @ sonkyu@googlemail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

// add the post menu item to the main menu
chrome.contextMenus.create({title: "@ the-coon", parentId: ewigenContextMenuReports, contexts:["selection"], onclick: coonPost});

function coonPost(info, tab) {
    var KB_START        = "Angreifer:";
    var KB_END          = "Statistik";
    
    var URL_PAGE        = "http://the-coon.org/kb/index.php";

    var val             = info.selectionText;
    
    // selected text is an actual fighting report
    if(val.indexOf(KB_START) > -1 && val.indexOf(KB_END) > -1) {
        // store the report locally
        localStorage['storedKB'] = val;
        // open the page in a new window
        chrome.tabs.create({"url":URL_PAGE, selected: true});
    }
}